home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 597 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: jamshid@io.com (Jamshid Afshar)
  3. Newsgroups: comp.std.c++
  4. Subject: wchar_t version of atof() and atoi()?
  5. Date: 29 Feb 1996 10:49:07 PST
  6. Organization: Illuminati Online, Austin, Texas, USA
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4h4oiv$4md@xanadu.io.com>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: 29 Feb 1996 11:42:55 -0600
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBVAwUBMTX1Nky4NqrwXLNJAQFkCAH/Wioo/VM3QBboBRbX72nW0j3UZQLJrddI
  13.     fcEpmwR7xlsr4lQPmDdUMruHDGA5SbIb1V9cpkyPE9dL6nmxOadPmw==
  14.     =07sL
  15. Originator: austern@isolde.mti.sgi.com
  16.  
  17. I'm new to internationalization issues but it's my understanding that
  18. Standard C++ will have very good support for it by way of the
  19. wide-character wstring and wifstream, etc. classes.  For example, a
  20. C++ program written in an environment that supports Unicode would
  21. strictly use wstring, wifstream, and wchar_t in place of string,
  22. ifstream, and char [1].  But, I didn't see a wchar_t* overload of
  23. functions like strtod() or atoi().  How are strings (eg, entered by a
  24. user into an edit box) supposed to be converted to numeric values in
  25. an internationalized C++ program?
  26.  
  27. I would do something like:
  28.  
  29.     int atoi( const wstring& s ) {
  30.        wistringstream strm(s);
  31.        int r;
  32.        s >> r;
  33.        if (s) return r;
  34.        else throw some_exception();
  35.     }
  36.  
  37. But stream i/o interprets "045" as an octal value instead of 45.
  38.  
  39. Also, it seems that if you want to write code that is portable to
  40. either a Unicode compiler/environment or a regular single-byte string
  41. environment you would have to introduce your own conditional typedefs
  42. for the string and stream classes, and consistently use those typdefs
  43. instead of directly using "string" or "wstring".  Does that sound
  44. right, or is there a technique using namespaces to solve this problem?
  45.  
  46. [1] It seems there's even "w" versions of the cin/cout (win/wout) and
  47. the argv char*'s are allowed to be multi-byte character strings which
  48. can be converted to wchar_t strings.
  49.  
  50. Jamshid Afshar
  51. jamshid@io.com
  52. ---
  53. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  54.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  55.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  56.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  57.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  58. ]
  59.